<?php

class User extends AdminController {

	public function __construct() {
		parent::__construct();
	}
	
	public function index() 
	{	
		$this->view->userList = $this->model->get();
		$this->view->render('user/index');
	}
	
	public function create() 
	{
		$this->model->create();
		header('location: ' . URL . 'user');
	}
        
    public function add()
    {
        $this->view->render('user/add');
    }
    
    public function view($id = null)
    {
        if ( $id == null)
            header('location: ' . URL . 'error');
        
        $this->view->user = $this->model->find($id);  
        $this->view->render('user/view');
    }
	
	public function edit($id=null) 
	{
	    if ( $id == null)
            header('location: ' . URL . 'error');
        
		$this->view->user = $this->model->find($id);
		$this->view->render('user/edit');
	}
	
	public function editSave($id=null)
	{
	    if ( $id == null)
            header('location: ' . URL . 'error');
        
		$this->model->editSave($id);
		header('location: ' . URL . 'user');
	}
	
	public function delete($id=null)
	{
	    if ( $id == null)
            header('location: ' . URL . 'error');
        
		$this->model->delete($id);
		header('location: ' . URL . 'user');
	}
}